package common.wx;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;

import common.impl.MicroBlog;

public class WxAccessToken {

	private final static String url_gettoken = "http://wxauth.1390mall.com/wxauth/wx/accounts_getaccesstoken.action?appId=APPID&appSecret=APPSECRET";

	/**
	 * 获取accessToken
	 * 
	 * @return
	 * @throws Exception
	 */
	public static String getAccessToken() throws Exception {
		String url = url_gettoken;
		url = url.replace("APPID", WxAuth.APPID);
		url = url.replace("APPSECRET", WxAuth.APPSECRET);
		String resp = MicroBlog.get(url, null);
		JSONObject jo = JSONObject.fromObject(resp);
		String accessToken = jo.getString("access_token");
		if (StringUtils.isEmpty(accessToken))
			return null;
		return accessToken;
	}

}
